package org.jeecg.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.jeecg.domain.OrdersServe;
import org.jeecg.domain.dto.OrdersServeDto;
import org.jeecg.domain.vo.OrderServeVo;
import org.jeecg.service.OrdersServeService;
import org.jeecg.mapper.OrdersServeMapper;
import org.jeecg.utils.ResponseResult;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
* @author 86182
* @description 针对表【orders_serve(服务单表)】的数据库操作Service实现
* @createDate 2024-12-26 09:06:00
*/
@Service
public class OrdersServeServiceImpl extends ServiceImpl<OrdersServeMapper, OrdersServe>
    implements OrdersServeService{
    @Resource
    private OrdersServeMapper ordersServeMapper;
    //任务列表分页+条件查询
    @Override
    public ResponseResult orderList(OrdersServeDto orderDto) {
        PageHelper.startPage(orderDto.getPageNum(),orderDto.getPageSize());
    List<OrderServeVo> orders = ordersServeMapper.orderList(orderDto);
    PageInfo<OrderServeVo> pageInfo = new PageInfo<>(orders);
    return ResponseResult.okResult(pageInfo);
    }


    //    根据任务id查询任务状态
    @Override
    public ResponseResult findTaskStatus(String id) {
        OrdersServe byId = this.getById(id);
        return ResponseResult.okResult(byId);
    }
    //    根据id查任务信息
    @Override
    public ResponseResult findTask(String id) {
        OrderServeVo vo=   ordersServeMapper.findTask(id);
        return ResponseResult.okResult(vo);
    }

    //    订单取消
    @Override
    public ResponseResult qux(String id) {
        OrdersServe byId = this.getById(id);
        if (byId != null ){
            if (byId.getTaskStatus() == 0 || byId.getTaskStatus() == 1 || byId.getTaskStatus() == 2){
                byId.setTaskStatus(5);
                boolean b = this.updateById(byId);
                return b?ResponseResult.okResult(200,"取消成功"):ResponseResult.errorResult(500,"取消失败");
            }else{
                return ResponseResult.errorResult(200,"不可取消");
            }
        }
        return ResponseResult.errorResult(500,"取消失败,该服务人员不存在");
    }
}




